<?php
	include_once("./global.php");
	session_start();
	if($_SESSION[id]){
		if(isset($_POST['update_app'])){
			if($_POST['app_overhead'] == '0'){
				$update = '0';
				$pushpid = '0';
			}else{
				$update = $_POST['app_overhead'];
				$apptrack = $result_select_detail['A_Apptrackid'];
				if(is_uploaded_file($_FILES['uploaded']['tmp_name'])){
					$uploaded = $_FILES["uploaded"];
					if($uploaded['error'] > 0){
						echo "<script>alert('上传出错，请重试')</script>";
					}else{
						if($uploaded["size"] <= '3145728'){
							$date = mktime();	
							$name = $_POST['uploaded_name'];
							$type = $_FILES['uploaded']['type'];
							$image_name = $name.$date;
							$path = "../images/";
							$file_pathname = "../images/".$name.".png";				
							if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$file_pathname)){
								$sql_insert_pic = "INSERT INTO pictureinfo(`P_PID`, `P_Name`, `P_ID`, `P_Path`, `P_Class`, `P_Adid`, `P_Adclass`, `P_Date`, `P_Url`) VALUES (NULL,'$name','$_POST[update_apptrackid]','$path','2','1','$update','$date',NULL)";
								$query_insert_pic = $mysqli->query($sql_insert_pic);
								if($query_insert_pic){
									$sql_select_pid = "select P_PID from pictureinfo where P_Date = '$date'";
									$query_select_pid = $mysqli->query($sql_select_pid);
									$result_select_pid = $query_select_pid->fetch_assoc();
									if($result_select_pid){
										$A_Apppadid = $result_select_pid['P_PID'];
									}else{
										echo "<script>alert('图片查询失败')</script>";
									}
								}else{
									echo "<script>alert('图片添加失败')</script>";
									echo $mysqli->error;
								}
							}else{
								echo "失败";
							}				
						}else{
							echo "<script>alert('图片太大')</script>";
						}
					}
				}else{
					echo "<script>alert('请选择你要上传的图片')</script>";
				}
				$sql_update_push = "update pushinfo set P_Pushartid = NULL, P_Pushappid='$_POST[update_apptrackid]',P_Pushpid = '$A_Apppadid' where P_Pushid = '$update' ";
				/*echo $sql_update_push;*/
				$query_update_push = $mysqli->query($sql_update_push);
				if($query_update_push){
					echo "<script>alert('push添加更新')</script>";
					$sql_select_push = "select P_Pushid,P_Pushpid from pushinfo where P_Pushappid = '$_POST[update_apptrackid]'";
					$query_select_push = $mysqli->query($sql_select_push);
					$result_select_push = $query_select_push->fetch_assoc();
					if($result_select_push){
						$update = $result_select_push['P_Pushid'];
						$pushpid = $result_select_push['P_Pushpid'];
						echo "<script>alert('push查询成功')</script>";
					}else{
						echo "<script>alert('pushid查询失败')</script>";
						echo $mysqli->error();
					}
				}else{
					echo "<script>alert('push更新失败')</script>";
					echo $mysqli->error();
				}
			}

			$date = mktime();
			$sql = "UPDATE `appinfo` SET `A_Class`='$_POST[update_class]',`A_Categoryid`='$_POST[update_category]',`A_Apptrackname`='$_POST[update_apptrackname]',`A_Appdesc`='$_POST[update_appdesc]',`A_Appkid`='$_POST[update_keyword]',`A_Appsystem`='$_POST[update_appsystem]',`A_Appartistname`='$_POST[update_appartistname]',`A_Apppid`='$_POST[update_appscreenshot]',`A_Appversion`='$_POST[update_appversion]',`A_Appicon`='$_POST[update_appicon]',`A_Appprice`='$_POST[update_price]',`A_Appfilesize`='$_POST[update_appfilesizebytes]',`A_Appreleasedate`='$_POST[update_appreleasedate]',`A_Apprating`='$_POST[update_apprating]',`A_Appcountratinguser`='$_POST[update_appcountratinguser]',`A_Applanguage`='$_POST[update_applanguage]',`A_Appdownload`='$_POST[update_appdownload]',`A_Appadid`='$update',`A_Apppadid`='$pushpid',`A_Appstatus`='1',`A_Applike`='$_POST[update_applike]',`A_Appjailbreak`='$_POST[update_appjailbreak]',`A_Appcount`='$_POST[update_appcount]',`A_Appdate`='$date' WHERE A_Apptrackid = '$_POST[update_apptrackid]'";
			$query = $mysqli->query($sql);
			if($query){
				echo "<script>alert('更新成功')</script>";
				echo "<meta http-equiv=\"refresh\" content=\"1; url='admin_app_mangerment.php?page=1' />";
			}else{
				echo "<script>alert('更新失败')</script>";
				echo $mysqli->error;
				echo "<meta http-equiv=\"refresh\" content=\"1; url='admin_app_edit.php?=".$_POST['update_apptrackid']."' />";
			}
		}
		if(isset($_POST['insert_app'])){
			$apptrackid = $_POST[insert_trackid][0];
			$appkid = $_POST[insert_keyword][0];
			
			$sql_select_app = "select * from appinfo where A_Apptrackid = '$apptrackid'";
			$query_select_app = $mysqli->query($sql_select_app);
			$result_select_app = $query_select_app->fetch_assoc();
			if($result_select_app){
				$sql_select_detail = "select * from appinfo where A_Appid = '$result_select_app[A_Appid]'";
				$query_select_detail = $mysqli->query($sql_select_detail);
				$result_select_detail = $query_select_detail->fetch_assoc();
				if($result_select_detail){
					echo "<script>alert('该APP已存在查询成功')</script>";
				}else{
					echo "<script>alert('查询失败')</script>";
					echo $mysqli->error;
				}			
			}else{
				$datetime = mktime();
				if($_POST[insert_appcategoryid][0]){					
					$sql_insert_app = "INSERT INTO appinfo(A_Appid,A_Class,A_Categoryid,A_Apptrackid,A_Apptrackname,A_Appdesc,A_Appkid,A_Appsystem,A_Apppid,A_Appversion,A_Appicon,A_Appprice,A_Appfilesize,A_Appreleasedate,A_Apprating,A_Appcountratinguser,A_Applanguage,A_Appdownload,A_Appadid,A_Apppadid,A_Appstatus,A_Applike,A_Appdate) VALUES (NULL,'0','$appcategoryid','$apptrackid','$_POST[insert_trackname]',NULL,'$appkid',NULL,NULL,NULL,NULL,'$_POST[insert_appprice]',NULL,NULL,'$_POST[insert_averageuserrating]','$_POST[insert_countuserrating]',NULL,'$_POST[insert_download]',NULL,NULL,'0','0','$datetime')";
				}else{
					$sql_insert_app = "INSERT INTO appinfo(A_Appid,A_Class,A_Categoryid,A_Apptrackid,A_Apptrackname,A_Appdesc,A_Appkid,A_Appsystem,A_Apppid,A_Appversion,A_Appicon,A_Appprice,A_Appfilesize,A_Appreleasedate,A_Apprating,A_Appcountratinguser,A_Applanguage,A_Appdownload,A_Appadid,A_Apppadid,A_Appstatus,A_Applike,A_Appdate) VALUES (NULL,'0',NULL,'$apptrackid','$_POST[insert_trackname]',NULL,'$appkid',NULL,NULL,NULL,NULL,'$_POST[insert_appprice]',NULL,NULL,'$_POST[insert_averageuserrating]','$_POST[insert_countuserrating]',NULL,'$_POST[insert_download]',NULL,NULL,'0','0','$datetime')";
				}
				echo $sql_insert_app;
				$query_insert_app = $mysqli->query($sql_insert_app);
				if($query_insert_app){
					echo "<script>alert('添加成功')</script>";
					$sql_select_detail = "select * from appinfo where A_Apptrackid = '$apptrackid'";
					$query_select_detail = $mysqli->query($sql_select_detail);
					$result_select_detail = $query_select_detail->fetch_assoc();
					if($result_select_detail){
						echo "<script>alert('查询成功')</script>";
					}else{
						echo "<script>alert('查询失败')</script>";
					}	
				}else{
					echo "<script>alert('".$app_trackId."添加失败')</script>";
					echo $mysqli->error."<br />";
				}
			}
		}
		if(isset($_POST['collect_app'])){
			$apptrackid = $_POST['itunes_term'];
			
			$sql_select_app = "select * from appinfo where A_Apptrackid = '$apptrackid'";
			$query_select_app = $mysqli->query($sql_select_app);
			$result_select_app = $query_select_app->fetch_assoc();
			if($result_select_app){
				$sql_select_detail = "select * from appinfo where A_Appid = '$result_select_app[A_Appid]'";
				$query_select_detail = $mysqli->query($sql_select_detail);
				$result_select_detail = $query_select_detail->fetch_assoc();
				if($result_select_detail){
					echo "<script>alert('该APP已存在查询成功')</script>";
				}else{
					echo "<script>alert('查询失败')</script>";
					echo $mysqli->error;
				}			
			}else{
				$datetime = mktime();
				if($_POST[insert_appcategoryid][0]){					
					$sql_insert_app = "INSERT INTO appinfo(A_Appid,A_Class,A_Categoryid,A_Apptrackid,A_Apptrackname,A_Appdesc,A_Appkid,A_Appsystem,A_Apppid,A_Appversion,A_Appicon,A_Appprice,A_Appfilesize,A_Appreleasedate,A_Apprating,A_Appcountratinguser,A_Applanguage,A_Appdownload,A_Appadid,A_Apppadid,A_Appstatus,A_Applike,A_Appdate) VALUES (NULL,'0','$appcategoryid','$apptrackid','$_POST[insert_trackname]',NULL,'$appkid',NULL,NULL,NULL,NULL,'$_POST[insert_appprice]',NULL,NULL,NULL,NULL,NULL,'$_POST[insert_download]',NULL,NULL,'0','0','$datetime')";
				}else{
					$sql_insert_app = "INSERT INTO appinfo(A_Appid,A_Class,A_Categoryid,A_Apptrackid,A_Apptrackname,A_Appdesc,A_Appkid,A_Appsystem,A_Apppid,A_Appversion,A_Appicon,A_Appprice,A_Appfilesize,A_Appreleasedate,A_Apprating,A_Appcountratinguser,A_Applanguage,A_Appdownload,A_Appadid,A_Apppadid,A_Appstatus,A_Applike,A_Appdate) VALUES (NULL,'0',NULL,'$apptrackid','$_POST[insert_trackname]',NULL,'$appkid',NULL,NULL,NULL,NULL,'$_POST[insert_appprice]',NULL,NULL,NULL,NULL,NULL,'$_POST[insert_download]',NULL,NULL,'0','0','$datetime')";
				}
				echo $sql_insert_app;
				$query_insert_app = $mysqli->query($sql_insert_app);
				if($query_insert_app){
					echo "<script>alert('添加成功')</script>";
					$sql_select_detail = "select * from appinfo where A_Apptrackid = '$apptrackid'";
					$query_select_detail = $mysqli->query($sql_select_detail);
					$result_select_detail = $query_select_detail->fetch_assoc();
					if($result_select_detail){
						echo "<script>alert('查询成功')</script>";
					}else{
						echo "<script>alert('查询失败')</script>";
					}	
				}else{
					echo "<script>alert('".$app_trackId."添加失败')</script>";
					echo $mysqli->error."<br />";
				}
			}
		}
			
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<title>后台首页</title>
<style>
	body{ background:#e7e7e7; margin:0; padding:0;}
	#container{ width:980px; height:auto; position:relative; margin:0 auto;}
	#container #header{ width:980px; height:90px; position:relative; background:#000; line-height:90px;color:#fff; font-size:24px; text-align:center;}
	.left{width:250px; height:auto; position:relative; float:left;}
	.left table{width:248px; height:auto; position:relative; float:left; background:#fff;}
	.left table td{ height:20px; text-align:center;}
	.left table .selected{ background:#73abe3;}
	#content{ width:730px; height:100%; position:relative; float:left; margin:2px 0px;}
	#content .title{ width:720px; height:25px; position:relative; float:left; line-height:25px; font-size:18px; color:#fff; background:#000;}
	form{margin:20px auto; width:720px; height:auto; position:relative; float:left;}
	form .inpuarea{ width:650px; height:450px;}
</style>
</head>
<body>
	<div id="container">
		<div id="header">
			818苹果站后台管理
		</div>
		<div class="left">
			<table>
				<tr><td style="background:#000000; color:#fff;">站点管理</td></tr>
				<tr><td><a href="admin_site_mangerment.php">全局管理</a></td></tr>
				<tr><td>静态页面管理</td></tr>
				<tr><td><a href="admin_link_mangerment.php?page=1">友情链接管理</a></td></tr>
				<tr><td><a href="admin_member_mangerment.php">会员管理</a></td></tr>
				<tr><td><a href="admin_tags_mangerment.php">标签管理</a></td></tr>
				<tr><td><a href="admin_search_mangerment.php">搜索管理</a></td></tr>
			</table>
			<table>
				<tr><td style="background:#000000; color:#fff;">文章管理</td></tr>
				<tr><td><a href="admin_category_mangerment.php">文章分类管理</a></td></tr>
				<tr><td><a href="admin_news_add.php">发布文章</a></td></tr>
				<tr><td><a href="admin_news_mangerment.php">文章管理</a></td></tr>
			</table>
			<table>
				<tr><td style="background:#000000; color:#fff;">应用管理</td></tr>
				<tr><td><a href="admin_appcate_mangerment.php">应用分类管理</a></td></tr>
				<tr><td><a href="admin_app_add.php">添加应用</a></td></tr>
				<tr><td><a href="admin_app_mangerment.php">应用管理</a></td></tr>
                <tr><td class="selected"><a href="admin_app_collection.php">应用采集</a></td></tr>
				<tr><td><a href="admin_app_collection_single.php">单应用采集</td></tr>
			</table>
		</div>

<?php
			
			$url = "https://itunes.apple.com/cn/app/id".$apptrackid;
			
			$str = file_get_contents($url);
			$keyword = "/<\/span><a href=\"(.*)\">(.*)<\/a>/Usi";
			$artistname = "/<div class=\"left\"><h1>(.*)<div class=\"right\">/Usi";
			$price = "/<ul class=\"list\"><li><div class=\"price\">(.*)<\/div><\/li>/Usi";
			$list = "/<li><span class=\"label\">(.*)<\/span>(.*)<\/li>/Usi";
			$language = "/<li class=\"language\"><span class=\"label\">(.*)<\/span>(.*)<\/li>/Usi";
			$date = "/<li class=\"release-date\"><span class=\"label\">(.*)<\/span>(.*)<\/li>/Usi";
			$icon_175 = "/<img width=\"175\" height=\"175\" alt=\"(.*)\" class=\"(.*)\" src=\"(.*)\" \/>/Usi";
			$screenshot = "/<div class=\"lockup\"><img alt=\"(.*)\"(.*)src=\"(.*)\" \/><\/div>/Usi";
			$meta = "/<meta name=\"keywords\" content=\"(.*)\" \/>/Usi";
			$desc = "/<div more-text=\"更多\" metrics-loc=\"Titledbox_内容提要\" class=\"product-review\">(.*)<h4>(.*)<\/h4>(.*)<p>(.*)<\/p>/Usi";
			$system = "/<p><span class=\"app-requirements\">(.*)<\/span>(.*)<\/p>/Usi";
			
			preg_match_all($artistname,$str,$artistname_arr);
			preg_match_all($keyword,$str,$keyword_arr);
			preg_match_all($price,$str,$price_arr);
			preg_match_all($list,$str,$list_arr);
			preg_match_all($date,$str,$date_arr);
			preg_match_all($language,$str,$language_arr);
			preg_match_all($icon_175,$str,$icon_arr);
			preg_match_all($desc,$str,$desc_arr);
			preg_match_all($screenshot,$str,$screen_arr);
			preg_match_all($meta,$str,$meta_arr);
			preg_match_all($system,$str,$system_arr);
			
			$keyword = $meta_arr[1][0];
			$keyword_explode = explode(",",$keyword);
			$count_keyword = count($keyword_explode);
			for($m=0;$m<$count_keyword;$m++){
				$check_en = $keyword_explode[$m];
				$check = preg_match("/^[^\x80-\xff]+$/",$check_en);
				if(!$check){
					$kid[] = $keyword_explode[$m];
				}else{
					continue;
				}
			}
			$A_Appicon = $icon_arr[3][0];
			$A_Apptrackname = $icon_arr[1][0];
			$A_Applanguage = $language_arr[2][0];
			$A_Appreleasedate = $date_arr[2][0];
			$A_Appprice = $price_arr[1][0];
			$A_Category = $keyword_arr[2][0];
			$A_Appversion = $list_arr[2][0];
			$A_Appfilesize = $list_arr[2][1];
			$A_Appartistname = $list_arr[2][2];	
			$A_Appdesc = $desc_arr[4][0];
			$A_Appsystem = $system_arr[2][0];		
			$count = count($screen_arr[3]);
			$count = $count/2;
			for($i=0;$i<$count;$i++){
				$screen[] = array("id"=>$i,"url"=>$screen_arr[3][$i]);
			}
/*			$url = "https://itunes.apple.com/lookup?id=".$apptrackid;
			$json_str = file_get_contents($url);
			if($json_str){
				$json_str;
				$json = json_decode($json_str);
				$json_single = $json->results[0];
				if($json_single != 0){
					$array = (array)$json_single;
				}else{
					$trackid = $_POST['insert_trackid'][0];
					$artistname =  preg_replace("/ /","+",$_POST['inser_atristname']);
					$url = "https://itunes.apple.com/search?term=".$artistname."&country=cn&entity=software";
					echo $url;
					$json_agstr = file_get_contents($url);
					if($json_agstr){
						$json_ag = json_decode($json_agstr);
						$total = $json_ag->resultCount;
						$i = '0';
						for($i=0;$i<$total;$i++){
							$json_test = $json_ag->results[$i];
							$array = (array)$json_test;
							if($array['trackId'] == $trackid){
							}
						}
					}
				}
			}else{
				echo "<script>alert('出错')</script>";
			}*/
	

?>
	<div id="content">
		<div class="title">发布APP</div>
		<form action="" method="post" enctype="multipart/form-data">
		<table>
			<tr>
				<td><label>APP标题</label></td><td><input type="text" name="update_apptrackid" value="<?php echo $apptrackid; /*echo $result_select_detail['A_Apptrackid']*/;?>" /><input class="input" type="text" name="update_apptrackname" size="50" value="<?php echo $A_Apptrackname; /*echo trim($result_select_detail['A_Apptrackname'])*/;?>"/>(最大长度25个字)</td>
			</tr>
            <tr>
				<td><label>APP分类</label></td><td>
                <?php if($result_select_detail['A_Class'] == '0'){?>
                <input type="radio" name="update_class" value="0" checked="checked"/>IOS_APP<input type="radio" name="update_category" value="1" />越狱APP
                <?php }else{?>
                <input type="radio" name="update_category" value="0"/>IOS_APP<input type="radio" name="update_category" value="1" checked="checked"/>越狱APP
                <?php }?>
                </td>
			</tr>
            <tr>
				<td><label>APP类别</label></td><td>
                <?php
					$categoryid = $result_select_detail['A_Categoryid'];
						$sql_select_categoryid = "select * from appcategoryinfo";
						$query_select_categoryid = $mysqli->query($sql_select_categoryid);
						while($result_select_categoryid = $query_select_categoryid->fetch_assoc()){
				?>
                <input type="radio" name="update_category" size="50" value="<?php echo $result_select_categoryid['AC_Categoryid'];?>" 
                <?php
                			if($result_select_categoryid['AC_Categoryid'] == $categoryid){
				?>
					checked="
                <?php 
                    			echo "checked";
							}
				?>
                "/>
				<?php 
							$categoryname = $result_select_categoryid['AC_Categoryname'];
							echo $categoryname;
							$sql_select_categorykid = "select K_KID from keywordinfo where K_Name = '$categoryname'";
							$query_select_categorykid = $mysqli->query($sql_select_categorykid);
							$result_select_categorykid = $query_select_categorykid->fetch_assoc();
							echo "(".$result_select_categorykid['K_KID'].")";?><!--<input type="radio" name="app_class" value="1" />动作<input type="radio" name="app_class" value="0"/>策略<input type="radio" name="app_class" value="0"/>休闲<input type="radio" name="app_class" value="0"/>射击-->
                <?php
                		}		
				?></td>
			</tr>
			<tr>
				<td><label>APP关键词</label></td><td>
				<input type="text"  size="50" name="update_keyword" value="
				<?php
					if($result_select_detail['A_Appkid']){
						$appkid = $result_select_detail['A_Appkid'];						
                		$appkid_explode = explode(',',$appkid);
						foreach($appkid_explode as $key=>$value){
							$value=$appkid_explode[$key];
							$sql_select_kid = "select K_Name from keywordinfo where K_KID = '$value'";
							$query_select_kid = $mysqli->query($sql_select_kid);
							while($result_select_kid = $query_select_kid->fetch_assoc()){
								echo $result_select_kid['K_Name']."(".$value.")".",";				
							}
						}
					}else{
						for($o=0;$o<count($kid);$o++){
							$kname = trim($kid[$o]);
							$sql_select_kid = "select K_KID from keywordinfo where K_Name = '$kname'";
							$query_select_kid = $mysqli->query($sql_select_kid);
							$result_select_kid = $query_select_kid->fetch_assoc();
							if($result_select_kid['K_KID']){
								echo $kname."(".$result_select_kid['K_KID']."),";
							}else{
								$sql_insert_kname = "insert into keywordinfo (K_KID,K_ID,K_Name,K_search,K_tags) values(NULL,NULL,'$kanme',NULL,'0')";
								/*echo $sql_insert_kname;*/
							}
						}
					}
				?>
				" />(最大长度50个字)</td>
                <!--<input class="input" type="text" name="app_keyword" value="" />(最大长度50个字)-->
			</tr>
				<td><label>APP价格</label></td>
                <td>
                    <input type="text" name="update_price"  size="50" value="<?php if($_POST['insert_appprice']){ echo $_POST['insert_appprice'];}else{echo $A_Appprice;}?>" />(精确到小数点后两位)</td>
			</tr>
            <tr>
            	<td><label>系统要求</label></td>
                <td><input type="text" name="update_appsystem" size="50" value="<?php echo trim($A_Appsystem) /*print_r($array['artistId'])*/;?>" />
                </td>
            </tr>
            <tr>
            	<td><label>APP厂商名称</label></td>
                <td><input type="text" size="50" name="update_appartistname" value="<?php echo $A_Appartistname /*print_r($array['artistName'])*/;?>" />
                </td>
            </tr>
            <tr>
            	<td><label>APP语言</label></td>
                <td><input type="text" size="50" name="update_applanguage" value="<?php echo $A_Applanguage/* $array['languageCodesISO2A'][0].",".$array['languageCodesISO2A'][1];*/?>" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP下载地址</label></td>
                <td><input type="text" size="50" name="update_appdownload" value="<?php echo $url?>" />
            	</td>
            </tr>
			<tr>
				<td><label>APP越狱下载地址</label></td>
				<td><input type="text" size="50" name="update_appjailbreak" value="<?php echo $result_select_detail['A_Appjailbreak'];?>" /></td>
			</tr>
			<tr>
				<td><label>APP下载次数</label></td>
				<td><input type="text" size="50" name="update_appcount" value="<?php echo $result_select_detail['A_Appcount']?>" /></td>
			</tr>
            <tr>
            <tr>
            	<td><label>APP喜欢人数</label></td>
                <td><input type="text" size="50" name="update_applike" value="<?php echo $result_select_detail['A_Applike'];?>" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP发布时间</label></td>
                <td><input type="text" size="50" name="update_appreleasedate" value="<?php echo $A_Appreleasedate /*print_r($array['releaseDate'])*/;?>" />
            	</td>
            </tr>
           	<tr>
            	<td><label>APP图标(60*60)</label></td>
                <td><input type="text" size="50" name="update_appicon" value="<?php echo $A_Appicon;?>" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP截图</label></td>
                <td><input size="50" name="update_appscreenshot" value="<?php 
					if($result_select_detail['A_Apppid']){
						echo $result_select_detail['A_Apppid'];
					}else{
						$n ='0';
						for($n=0;$n<$count;$n++){
							$screen_url = trim($screen[$n][url]);
							$sql_select_check = "select P_PID from pictureinfo where P_Url = '$screen_url'";
							$query_select_check = $mysqli->query($sql_select_check);
							$result_select_check = $query_select_check->fetch_assoc();
							if($result_select_check['P_PID']){
								print_r($result_select_check['P_PID']);
								echo ",";
								/*echo $resule_select_check['P_PID'].",";*/
							}else{
								if($result_select_detail){
									$sql_insert_pid = "insert into pictureinfo (`P_PID`, `P_Name`,`P_ID`,`P_Path`, `P_Class`, `P_Adid`, `P_Adclass`, `P_Date`, `P_Url`) values (NULL,'$result_select_detail[A_Apptrackname]','$result_select_detail[A_Apptrackid]',NULL,'1',NULL,NULL,NULL,'$screen_url')";
								}else{
									$sql_insert_pid = "insert into pictureinfo (`P_PID`, `P_Name`,`P_ID`,`P_Path`, `P_Class`, `P_Adid`, `P_Adclass`, `P_Date`, `P_Url`) values (NULL,'$A_Apptrackname','$apptrackid',NULL,'1',NULL,NULL,NULL,'$screen_url')";
								
								}
								$query_insert_pid = $mysqli->query($sql_insert_pid);		
								if($query_insert_pid){
									$sql_select_pid = "select P_PID from pictureinfo where P_Url = '$screen_url'";
									$query_select_pid = $mysqli->query($sql_select_pid);
									while($result_select_pid = $query_select_pid->fetch_assoc()){
										echo $result_select_pid['P_PID'].",";
									}								
								}else{
									echo $mysqli->error;
								}
							}
						}
					}

					?>" /></td>
            </tr>
            <tr>
            	<td><label>APP大小</label></td>
                <td><input type="text" size="50" name="update_appfilesizebytes" value="<?php echo $A_Appfilesize; /*$filesize = floor($array['fileSizeBytes']/1024/1024); echo $filesize;*/?>" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP评分</label></td>
                <td><input type="text" size="50" name="update_apprating" value="<?php echo $_POST['insert_averageuserrating'];?>" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP评分人数</label></td>
                <td><input type="text" size="50" name="update_appcountratinguser" value="<?php echo $_POST['insert_countuserrating'];?>" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP版本号</label></td>
                <td><input type="text" size="50" name="update_appversion" value="<?php echo $A_Appversion /*print_r($array['version'])*/;?>" />
                </td>
            </tr>
				<td><label>幻灯推送位置</label></td><td><input type="checkbox" name="app_overhead" value="0" />无推广<input type="checkbox" name="app_overhead" value="1" />幻灯1<input type="checkbox" name="app_overhead" value="2" />幻灯2<input type="checkbox" name="app_overhead" value="3" />幻灯3<input type="checkbox" name="app_overhead" value="4" />幻灯4<input type="checkbox" name="app_overhead" value="5" />幻灯5<input type="checkbox" name="app_overhead" value="6" />幻灯6<input type="checkbox" name="app_overhead" value="7" />幻灯7<input type="checkbox" name="app_overhead" value="8" />幻灯8<input type="checkbox" name="app_overhead" value="9" />幻灯9<input type="checkbox" name="app_overhead" value="10" />幻灯10<input type="checkbox" name="app_overhead" value="11" />首页左侧推广1<input type="checkbox" name="app_overhead" value="12" />首页左侧推广2<input type="checkbox" name="app_overhead" value="13" />首页限免1<input type="checkbox" name="app_overhead" value="14" />首页限免2<input type="checkbox" name="app_overhead" value="15" />首页限32<input type="checkbox" name="app_overhead" value="16" />首页限免4<input type="checkbox" name="app_overhead" value="17" />首页限免5<input type="checkbox" name="app_overhead" value="18" />首页限免6<input type="checkbox" name="app_overhead" value="18" />右侧推广1<input type="checkbox" name="app_overhead" value="9" />右侧推广2</td>
			</tr>
			<tr>
				<td><label>限免推送位置</label></td><td><input type="checkbox" name="app_overhead" value="13" />首页限免1<input type="checkbox" name="app_overhead" value="14" />首页限免2<input type="checkbox" name="app_overhead" value="15" />首页限32<input type="checkbox" name="app_overhead" value="16" />首页限免4<input type="checkbox" name="app_overhead" value="17" />首页限免5<input type="checkbox" name="app_overhead" value="18" />首页限免</td>
			</tr>
			<tr>
				<td><label>右侧推送位</label></td><td><input type="checkbox" name="app_overhead" value="21" />右侧APP推广1<input type="checkbox" name="app_overhead" value="22" />右侧APP推广2</td>
			</tr>
			<tr>
				<td><label>列表推送位</label></td><td><input type="checkbox" name="app_overhead" value="23" />列表推广1<input type="checkbox" name="app_overhead" value="24" />列表推广2<input type="checkbox" name="app_overhead" value="25" />列表推广3<input type="checkbox" name="app_overhead" value="26" />列表推广4<input type="checkbox" name="app_overhead" value="27" />列表推广5<input type="checkbox" name="app_overhead" value="28" />列表推广6<input type="checkbox" name="app_overhead" value="29" />列表推广5<input type="checkbox" name="app_overhead" value="30" />列表推广8</td>
            <tr>
            	<td><label>配图</label></td><td><input type="file" name="uploaded" /><input type="text" name="uploaded_name" /></td>
            </tr>
			<tr>
				<td><label>APP描述</label></td><td><textarea class="inpuarea" name="update_appdesc"  />
                <?php
                	echo $A_Appdesc;
				?>
                </textarea>(最大长度120个字)</td>
			</tr>
			<tr>
				<td><input type="submit" name="update_app" value="提交" /></td>
			</tr>
		</table>
		</form>
        </table>
	</div>
</div>
</body>
</html>
<?php
	}else{
		echo "<script>alert('登录先')</script>";
		echo "<meta http-equiv=\"refresh\" content=\"1; url='admin_login.php' />";
	}
?>